package com.hxy.user.controller;

import com.hxy.basic.exception.BusinessExcpetion;
import com.hxy.basic.query.util.AjaxResult;
import com.hxy.user.dto.LoginDto;
import com.hxy.user.service.ILoginInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;


/**
 * 登录Controller
 */
@RestController
@RequestMapping("/login")
public class LoginController {

    @Autowired
    private ILoginInfoService loginInfoService;

    /**
     * 账户登录方法
     */
    @PostMapping("/account")
    public AjaxResult accountlogin(@RequestBody LoginDto loginDto){
        try {
            return loginInfoService.accountLogin(loginDto);
        } catch (BusinessExcpetion e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMsg("登录失败，"+e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMsg("系统错误，"+e.getMessage());
        }
    }
    /**
     * 微信登录方法
     */
    @PostMapping("/wxUser")
    public AjaxResult wxUserLogin(@RequestBody Map<String,String> map){
        try {
            return loginInfoService.wxUserLogin(map);
        } catch (BusinessExcpetion e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMsg("登录失败，"+e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMsg("系统错误，"+e.getMessage());
        }
    }
    /**
     * 微信绑定方法
     * /login/binder/wechat",this.phoneUserForm)
     *
     */
    @PostMapping("/binder/wechat")
    public AjaxResult wxUserBinder(@RequestBody Map<String,String> map){
        try {
            return loginInfoService.wxUserBinder(map);
        } catch (BusinessExcpetion e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMsg("登录失败，"+e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMsg("系统错误，"+e.getMessage());
        }
    }

}













